# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=gtkmm
pkgbase=mingw-w64-${_realname}-4.0
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-4.0"
pkgver=4.18.0
pkgrel=2
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}4")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}4")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}4")
pkgdesc="C++ bindings for GTK+4 (mingw-w64)"
msys2_repository_url='https://gitlab.gnome.org/GNOME/gtkmm'
url="https://www.gtkmm.org/"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-cairomm-1.16"
         "${MINGW_PACKAGE_PREFIX}-glibmm-2.68"
         "${MINGW_PACKAGE_PREFIX}-gtk4"
         "${MINGW_PACKAGE_PREFIX}-pangomm-2.48")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
sha256sums=('2ee31c15479fc4d8e958b03c8b5fbbc8e17bc122c2a2f544497b4e05619e33ec')

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--buildtype=release")
  else
    _extra_config+=("--buildtype=debug")
  fi

  CFLAGS+=" -Wno-attributes" \
  CXXFLAGS+=" -Wno-attributes" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    "${_extra_config[@]}" \
    --wrap-mode=nodownload \
    --default-library=both \
    --auto-features=enabled \
    -Dmaintainer-mode=false \
    -Dbuild-documentation=false \
    -Dbuild-demos=false \
    -Dbuild-tests=true \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/meson.exe test || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-4.0/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.tools" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-4.0/COPYING.tools"
}
